-
Notifications
You must be signed in to change notification settings - Fork 15
/
Tower In Cities.py
43 lines (36 loc) · 1.17 KB
/
Tower In Cities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Contribution By: Shantanu Gupta
# Github: Shantanugupta1118
# DAY 3 of DAY 100
# HackWithInfy'21 - Qualification Round - Tower Installation in Cities
'''
Test Case:
5 //N |
2 //R | Output: 1
[1,2,3,4,5] //cities distance |
---------------------------------------------------------------
5 |
0 | Output: 5
[8,16,32,4,2] |
---------------------------------------------------------------
4 |
10 | Output: 2
[42,31,5,19] |
---------------------------------------------------------------
'''
def sol(n, r, cities):
cities.sort()
numOfTower = 0
i = 0
while(i<n) :
numOfTower += 1
loc = cities[i] + 2*r
while (i < n and cities[i] <= loc):
i += 1
return numOfTower
def main():
n = int(input())
r = int(input())
ls = []
for i in range(n): ls.append(int(input()))
print(sol(n, r, ls))
main()